/**
 * 
 */
package com.nari.interfaces.decipher.gprs.protocolcodec;

import java.nio.charset.Charset;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

/**
 * 基于帧协议的编解码工厂实现
 * @author Xiaopeng
 * @date 2013-11-4
 */
public class FrameProtocolCodecFactory implements ProtocolCodecFactory {
	private FrameProtocolEncoder frameEncoder;
	private FrameProtocolDecoder frameDecoder;
	
	/**
	 * 根据系统默认字符编码构建编解码工厂实例
	 * @param charset
	 */
	public FrameProtocolCodecFactory() {
		this(Charset.defaultCharset());
	}
	
	/**
	 * 根据指定字符编码构建编解码工厂实例
	 * @param charset
	 */
	public FrameProtocolCodecFactory(Charset charset) {
		this.frameEncoder = new FrameProtocolEncoder(charset);
		this.frameDecoder = new FrameProtocolDecoder(charset);
	}
	
	/**
	 * 获取帧协议解码器
	 * @param session
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-11-4
	 */
	public ProtocolDecoder getDecoder(IoSession session) throws Exception {
		return this.frameDecoder;
	}

	/**
	 * 获取帧协议编码器
	 * @param session
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-11-4
	 */
	public ProtocolEncoder getEncoder(IoSession session) throws Exception {
		return this.frameEncoder;
	}

}
